import { useMemo } from 'react'
import { View } from '@tarojs/components'
import { useResetDate, useTitleCut } from '@/utils/myUtils'
import './index.scss'

function CardA(props) {

    const stateColor = {
        active: {
            color: '#333333',
            fontWeight:'700'
        },
        unActive: {
            color: '#999999'
        }
    }

    const {
        data,
        isAdmin = false,
        onClick,
        state
    } = props

    const tag = useMemo(() => {
        if (isAdmin) {
            if (data?.status == 0) {
                return <View className='tag' style={{
                    color: '#ff6600',
                    backgroundColor: '#ffefe5',
                }}>未发布</View>
            } else {
                return <View className='tag' style={{
                    color: '#009900',
                    backgroundColor: '#e5f5e5',
                }}>已发布</View>
            }
        } else {
            return <></>
        }
    }, [data])



    return (
        <View
            key={data.bulletinId}
            className='card_container_A'
            onClick={(e) => onClick(data,e)}
        >
            {
               data.status==1&& isAdmin && data?.seat == 1 ?
                    <View className='topped'></View> : ""
            }
            <View className='icon'></View>
            <View className='card_body'>
                <View
                    className='title'
                    style={stateColor[state]}>
                    {useTitleCut(data.title, 40)}
                    {tag}
                </View>
                <View className='footer'>
                    <View className='footer_item'>{data?.typeName || '--'}</View>
                    <View className='footer_item'>{data?.departmentName || '--'}</View>
                    <View className='footer_item'>{useResetDate(data.releaseTime)}</View>
                </View>
            </View>
        </View>
    );
}




export default function App(props) {
    let {
        type
    } = props

    if (type === 'A') {
        return <CardA {...props} />
    } else {
        return <CardA {...props} />
    }
}

